package com.bl.student.manager.controller.order;

import com.bl.student.common.ApiResponseBody;
import com.bl.student.common.enums.SearchType;
import com.bl.student.manager.controller.BaseController;
//import com.bl.student.service.biz.ico.IcoService;
import com.bl.student.service.biz.order.OrderService;
//import com.bl.student.service.vo.DelBody;
//import com.bl.student.service.vo.DelListBody;
//import com.bl.student.service.vo.ico.IcoAddVo;
//import com.bl.student.service.vo.ico.IcoListVo;
//import com.bl.student.service.vo.ico.IcoModVo;
import com.bl.student.service.vo.order.OrderListVo;
import com.bl.student.service.vo.order.OrderAddVo;
import com.bl.student.service.vo.order.OrderModVo;
//import com.bl.student.service.vo.withdrawals.WithdrawalsListVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

/**
 * Created by liangweikang on 18/12/26.
 */
@RestController
@Log4j2
@RequestMapping(value = {"/student/manager/order"})
@Api(value = "订单相关api", description = "订单相关api")
public class OrderController extends BaseController{

    @Autowired
    OrderService orderService;

    @ApiOperation(value = "订单列表", notes = "订单列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "partybId", value = "乙方id", required = false, paramType = "query", dataType = "String", defaultValue = ""),
            @ApiImplicitParam(name = "goodsId", value = "商品id", required = false, paramType = "query", dataType = "String", defaultValue = ""),
            @ApiImplicitParam(name = "ordersn", value = "订单号", required = false, paramType = "query", dataType = "String", defaultValue = ""),
            @ApiImplicitParam(name = "express", value = "运单号", required = false, paramType = "query", dataType = "String", defaultValue = ""),
            @ApiImplicitParam(name = "status", value = "订单状态", required = false, paramType = "query", dataType = "String", defaultValue = ""),
            @ApiImplicitParam(name = "page", value = "页数", required = true, paramType = "query", dataType = "int", defaultValue = "1"),
            @ApiImplicitParam(name = "size", value = "每页大小", required = true, paramType = "query", dataType = "int", defaultValue = "10")})
    @GetMapping(value = {"/get_list_multi"})
    public ApiResponseBody<OrderListVo> getListMulti(
            @RequestParam(value = "partybId", required = false, defaultValue = "") String partybId,
            @RequestParam(value = "goodsId", required = false, defaultValue = "") String goodsId,
            @RequestParam(value = "ordersn", required = false, defaultValue = "") String ordersn,
            @RequestParam(value = "express", required = false, defaultValue = "") String express,
            @RequestParam(value = "status", required = false, defaultValue = "") String status,
            @RequestParam(value = "page", required = true, defaultValue = "1") int page,
            @RequestParam(value = "size", required = true, defaultValue = "10") int size,
            HttpServletRequest request) {

        Pageable pageable = new PageRequest(page - 1, size);

        OrderListVo icoListVo = orderService.getOrderListsMulti(partybId, goodsId, ordersn, express, status, pageable);

        return ApiResponseBody.createSuccessBody(icoListVo);
    }

    @ApiOperation(value = "修改订单", notes = "修改订单")
    @ApiImplicitParams({})
    @PostMapping(value = {"/modify"})
    public ApiResponseBody modify(
            @Valid @RequestBody OrderModVo body, BindingResult result,
            HttpServletRequest request) {

        ApiResponseBody validResult = validParams(result);
        if (validResult != null) {
            return validResult;
        }

        orderService.mod(body);

        return ApiResponseBody.createSuccessBody(null);
    }
}
